<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/messagebox.css?v=2">
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("留言");

        var app = new Vue({
            el: '#container',
            data: {
                info: [],
            },
            methods: {

                index: indexPage,
                checkRole: function(employeeRoleId, roleId) {
                    var employeeRoleArr = employeeRoleId.split(",");
                    var roleArr = roleId.split(",");

                    var result = false;
                    $.each(roleArr, function(i,val){
                        if($.inArray(val, employeeRoleArr) != -1 || $.inArray((parseInt(val)+100).toString(), employeeRoleArr) != -1){
                            result = true;
                        }
                    });
                    return result;
                },
                cancel: function() {
                    window.location.href = "/wechat";
                },
                copyText: function() {
                    var input = document.getElementById("copy");
                    input.select();
                    document.execCommand("copy");
                    alert("微信号复制成功");
                },
                submit: function() {

                    var messageId = $("input[name=messageId]").val();
                    var customerId = $("input[name=customerId]").val();
                    var number = $("input[name=number]").val();
                    var employeeId = $("select[name=employeeId]").val();
                    var nickname = $("input[name=nickname]").val();
                    var city = $("input[name=city]").val();
                    var createTime = $("input[name=createTime]").val();
                    var doctor = $("input[name=doctor]").val();
                    var hospital = $("input[name=hospital]").val();
                    var productId = $("select[name=productId]").val();
                    var productName = $("input[name=productName]").val();
                    var wechatid = $("input[name=wechatid]").val();
                    var diagnosis = $("textarea[name=diagnosis]").val();
                    var messageContent = $("textarea[name=messageContent]").val();

                    if(isNullOrEmpty(employeeId)) {
                        alert("请选择要通知的员工");
                        return false;
                    }

                    if(isNullOrEmpty(nickname)) {
                        alert("请填写用户昵称");
                        return false;
                    }

                    if(isNullOrEmpty(city)) {
                        alert("请填写所在城市");
                        return false;
                    }

                    if(isNullOrEmpty(number)) {
                        alert("请填写联系电话");
                        return false;
                    }
                    if(!checkPhone(number)) {
                        alert("联系电话位数不对");
                        return false;
                    }

//                    if(isNullOrEmpty(productId)) {
//                        alert("请选择产品");
//                        return false;
//                    }

//                    if(isNullOrEmpty(messageContent)) {
//                        alert("请填写留言");
//                        return false;
//                    }


                    $.ajax({
                        url:"/wechat/Messagebox/notify",
                        type:"post",
                        data:{
                            messageId: messageId,
                            customerId: customerId,
                            employeeId: employeeId,
                            nickname:nickname,
                            city: city,
                            createTime: createTime,
                            doctor: doctor,
                            hospital: hospital,
                            number: number,
                            productId: productId,
                            productName: productName,
                            wechatid: wechatid,
                            diagnosis: diagnosis,
                            messageContent: messageContent,
                        },

                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code == 200) {
                                alert("提交成功");
                                window.location.href = "/wechat/";
                            }
                        },
                    })

                }

            }
        })

        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("input[type=date]").change(function() {
            var value = $(this).val();
            $(this).prev().val(value);
        });

    });


</script>
<div class="edit-content">
    <input type="text" style="display: none;" name="messageId" value="{$messagebox.messagebox_id}">
    <input type="text" style="display: none;" name="customerId" value="{$customerId}">
    <div class="item" v-if="checkRole('{$role}', '1,3')">
        <span>通知给</span>
        <input id="employeeId" type="text" name="employeeName" value="" readonly placeholder="请选择">
        <select name="employeeId">
            <option value="">请选择通知人员</option>
            {:getEmployeeSelectOptionHtml($user['enterprise_code'],0)}
        </select>
        <img class="icon-right disease" src="/Template/images/icon-right.png" alt="">
        <p class="address" v-if="'{$messagebox.notified}' != ''" >
            已通知：{$messagebox.notified}
        </p>
    </div>
    <!--<div class="item">-->
        <!--<p class="address">已通知：{$messagebox.notified}</p>-->
    <!--</div>-->
    <div class="item">
        <span>用户昵称</span>
        <input type="text" name="nickname" value="{$customer.nickname}" placeholder="请填写">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="item">
        <span>留言时间</span>
        <input type="text" name="createTime" value="{$messagebox.create_time}" readonly>
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <!--div class="item" v-if="'{$customer.doctor_name}' != ''" >
        <span>所属医生</span>
        <input type="text" name="doctor" value="{$customer.doctor_name}" placeholder="请填写">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="item" v-if="'{$customer.hospital_name}' != ''" >
        <span>所属医院</span>
        <input type="text" name="hospital" value="{$customer.hospital_name}" placeholder="请填写">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div-->
    <div class="item">
        <span>所在城市</span>
        <input type="text" name="city" value="{$messagebox.city}" placeholder="请填写您所在城市名称">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="item">
        <span>联系电话</span>
        <input type="text" name="number" value="{$messagebox.number}" placeholder="请填写您的电话号码" style="display:none">
        <a href="tel://{$messagebox.number}">{$messagebox.number}</a>
        <!--<img class="icon-right" src="/Template/images/icon-right.png" alt="">-->
    </div>
    <div class="item" v-if="{$messagebox.wechatid} != ''">
        <span>微信号</span>
        <input type="text" id="copy" name="wechatid" value="{$messagebox.wechatid}" placeholder="" style="font-size: 1.2rem; color: #33b835" v-on:click="copyText()">
        <!--<img class="icon-right" src="/Template/images/icon-right.png" alt="">-->
    </div>
    <div class="item">
        <span>产品</span>
        <input id="productId" type="text" name="productName" value="{$ownProduct.product_name}" readonly placeholder="请选择产品">
        <select name="productId">
            <option value="">请选择</option>
            {:getProductSelectOptionHtml($messagebox['product_id'], 0)}
        </select>
        <img class="icon-right disease" src="/Template/images/icon-right.png" alt="">
    </div>
    <div v-if="{$messagebox.product_id} == 2">
        <div class="title-span">
            <span>症状或医生诊断</span>
        </div>
        <div class="area">
            <textarea class="t-area" name="diagnosis" placeholder="">{$messagebox.diagnosis}</textarea>
        </div>
    </div>
    <div class="title-span">
        <span>留言</span>
    </div>
    <div class="area">
        <textarea class="t-area" name="messageContent" placeholder="请填写您的留言">{$messagebox.message_content}</textarea>
    </div>
</div>

<div class="operation-btn">
    <div class="cancel-btn" v-on:click="cancel">取消</div>
    <div class="save-btn" v-on:click="submit" v-if="checkRole('{$role}', '1,3')">提交</div>
</div>
<include file="./Template/footer.html" />

